
import bg.cookbook.Locker;
import bg.cookbook.SlideCreator;

import flash.utils.Timer;

import mx.collections.ArrayCollection;
import mx.controls.Alert;

import org.osmf.events.TimeEvent;

import spark.filters.GlowFilter;

private var _isSlide1Visible:Boolean=true;
private var _isSlide2Visible:Boolean=true;
[Bindable]
private var _arrImg:Vector.<Locker>;
private var _index:int=0;
private var _timer:Timer;
[Bindable]
[Embed(source="/assets/prev.png")]
private var prev:Class;
[Bindable]
[Embed(source="/assets/play.png")]
private var play:Class;
[Bindable]
[Embed(source="/assets/pause.png")]
private var pause:Class;
[Bindable]
[Embed(source="/assets/next.png")]
private var next:Class;
[Bindable]
public var visibility:Boolean = false;
private var W:Number=1200;
private var H:Number=700;
import flash.utils.clearTimeout;
import flash.utils.setTimeout;

import mx.events.FlexEvent;
import mx.utils.OnDemandEventDispatcher;

import spark.components.Application;
import flash.events.MouseEvent;
import flash.ui.Mouse;
import flash.events.TimerEvent;
import mx.events.CloseEvent;
import flash.events.Event;

protected var _timeoutId:int;
protected function group1_mouseMoveHandler(event:MouseEvent):void
{
	Mouse.show();
	fadeOut.stop();
	visibility=true;
	clearTimeout(_timeoutId);
	_timeoutId=setTimeout(hideButtons, 1000);
	
}
protected function hideButtons():void
{
	visibility=false;
	Mouse.hide();
}

protected function image2_clickHandler(event:MouseEvent):void
{
	stopSlideshow();
}


protected function image3_clickHandler(event:MouseEvent):void
{
	playSlideshow(3000);
}
protected function image4_clickHandler(event:MouseEvent):void
{
	
}


protected function ESC_clickHandler(event:MouseEvent):void
{
	stopSlideshow();
	Mouse.show();
	clearTimeout(_timeoutId);
	this.dispatchEvent(new CloseEvent(CloseEvent.CLOSE));
}
public function playSlideshow(duration:int=1000):void
{
	if(_timer)
	{
		_timer.stop();
	}
	_timer= new Timer(duration);
	_timer.addEventListener(TimerEvent.TIMER,switchToNext,false,0,true);
	_timer.start();
}
protected function image1_clickHandler(event:MouseEvent):void
{
	startAnimation(); 
}
public function stopSlideshow():void
{
	if(_timer)
	{
		_timer.stop();
		_timer=null;
	}
}
public function get listOfSlides():Vector.<Locker>
{
	return _arrImg;
}
private function switchToNext(event:TimerEvent):void
{
	startAnimation();
}
public function startAnimation():void
{
	if(_isSlide1Visible)
	{
		hide.play([slide1]);
		show.play([slide2]);
	} else 
	{
		hide.play([slide2]);
		show.play([slide1]);
	}
	_isSlide1Visible=!_isSlide1Visible;
}
public function set listOfSlides(value:Vector.<Locker>):void
{
	_arrImg = value;
	if(_arrImg.length > 0)
	{
		_arrImg[0].fit(W,H);
		slide1.addElement(_arrImg[0]);
		loadNext();				
	}
}
private function loadNext(): void
{
	_index=(_index+1)%_arrImg.length;
	if(_isSlide1Visible)
	{
		_arrImg[_index].fit(W,H);
		slide2.addElement(_arrImg[_index]);
	}
	else
	{
		_arrImg[_index].fit(W,H);
		slide1.addElement(_arrImg[_index]);
	}
}
public function jump(data:int):void
{
	if(_isSlide1Visible)
	{
		//slide2.source = data;
	}
	else
	{
		//img1.source =data;
	}
	startAnimation();
}